home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: system() & error detection
- Date: Thu, 29 Feb 96 00:05:00 GMT
- Organization: none
- Message-ID: <825552300snz@genesis.demon.co.uk>
- References: <4gt24g$dba@ncar.ucar.edu> <4gt7f4INNt1j@keats.ugrad.cs.ubc.ca>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <4gt7f4INNt1j@keats.ugrad.cs.ubc.ca>
- c2a192@ugrad.cs.ubc.ca "Kazimir Kylheku" writes:
-
- >In article <4gt24g$dba@ncar.ucar.edu>,
- >James Adams <jadams@sage.cgd.ucar.edu> wrote:
- > >Hello,
- > >
- > > I am attempting to use the system() call in order to have a
- > >user-specified command execute in my program.
- > >
- > > I am wondering how I can check whether or not the command has
- > >completed successfully ? I don't want the program to continue if the
- > >call I make from system() produces some sort of error. I'd like to be
- > >able to do something like the following:
- > >
- > > result = system(command);
- > > if (result == ERROR)
- > > exit(0);
- > >
- > >Is there anyway to do this ? Should I be using something other than
- > >system() ?
- >
- >Try one of the member of the ``exec'' family of functions. These are defined by
- >the POSIX.1 standard, not ISO/ANSI C.
-
- Eh? exec*() replaces the currently executing program with the new one. Once
- the new program is successfully started the old one can never be resumed.
-
- >Exec lets you get the return value.
-
- All you can ever get is a failure code if the new program couldn't be
- executed. you were probably thinking of a combination of fork(), exec*()
- and wait*(). Pure comp.unix.programmer fodder however.
-
- >It is also more secure, since system() can
- >be exploited in ways which violate system security.
-
- However system() is an ANSI function and it does return a result code which
- will probably serve in this case. It is implementation defined as far as
- C is concerned. According to Lewine "The POSIX.2 standard provides several
- hundred pages of documentation on the arguments to system()." :-)
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-